require 'submail'
module Quickstep::MessageSupport extend ActiveSupport::Concern
  included do
    after_create :send_message
  end

  private
  def send_message
    if Rails.env.production?
      messagexsend = MessageXSend.new(MESSAGE_CONFIG)
      unless vars.blank?
        JSON.parse(vars).each do |key, value|
          messagexsend.add_var(key, value)
        end
      end
      messagexsend.add_to(recipient)
      messagexsend.set_project(template)
      messagexsend.message_xsend()
    end
    logger.info "SMS sent, #{template} to #{recipient}"
  end
end
